package com.hc.ssm.controller;

import com.hc.ssm.pojo.Member;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@RestController
public class MemberController{

    @RequestMapping("/getMember")
    public String getMember(){
        return "尊贵的梅萨德斯车主:老八[0]";
    }//更换端口

    @RequestMapping("/getMemberList")
    public List<Member> getMemberList(){
        List<Member> list = new ArrayList<>();
        list.add(new Member(1,"老王"));
        list.add(new Member(2,"老八"));
        list.add(new Member(3,"张三 "));
        return list;
    }

    @RequestMapping("/addMember")
    public void  addMember(@RequestBody Member member){
        System.out.println("-----------------------------------------");
        System.out.println(member);
        System.out.println("-----------------------------------------");
    }

    @RequestMapping("/getMemberById")
    public String getMember0(Integer id){
        return "尊贵的梅萨德斯车主:"+id;
    }

    @RequestMapping("/getMemberById2")
    @HystrixCommand(fallbackMethod = "processHystrix")
    public Member getMember2(Integer id){
        if (id==0){
           throw  new RuntimeException("该"+id+"存在异常！！！");
        }

        return new Member(id,"老王");
    }

    public Member processHystrix(Integer id){

        return new Member(-1,"当前系统出现问题,请联系管理员。");
    }

}
